package com.agileboot.domain.performance.teaching.model;

import cn.hutool.core.bean.BeanUtil;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.performance.teaching.command.AddTeachingWorkloadCommand;
import com.agileboot.domain.performance.teaching.command.UpdateTeachingWorkloadCommand;
import com.agileboot.domain.performance.teaching.db.TeachingWorkloadEntity;
import com.agileboot.domain.performance.teaching.db.TeachingWorkloadService;
import lombok.NoArgsConstructor;

/**
 * 教学工作量模型
 */
@NoArgsConstructor
public class TeachingWorkloadModel extends TeachingWorkloadEntity {

    private TeachingWorkloadService teachingWorkloadService;

    public TeachingWorkloadModel(TeachingWorkloadService teachingWorkloadService) {
        this.teachingWorkloadService = teachingWorkloadService;
    }

    public TeachingWorkloadModel(TeachingWorkloadEntity entity, TeachingWorkloadService teachingWorkloadService) {
        if (entity != null) {
            BeanUtil.copyProperties(entity, this);
        }
        this.teachingWorkloadService = teachingWorkloadService;
    }

    public void loadFromAddCommand(AddTeachingWorkloadCommand addCommand) {
        if (addCommand != null) {
            BeanUtil.copyProperties(addCommand, this, "id");
        }
    }

    public void loadFromUpdateCommand(UpdateTeachingWorkloadCommand command) {
        if (command != null) {
            loadFromAddCommand(command);
        }
    }

    public void checkCanBeDeleted() {
        // 这里可以根据实际需求添加删除前的验证逻辑
    }

    public void checkUnique() {
        // 在此处添加您需要的唯一性验证（例如教学工作量的特殊要求）
    }

}
